//
// Created by ningjian on 2021/10/11.
//
#include "musebin.h"

CMat * DecodeBinData(const uint8_t * data_ptr, size_t data_len, int total_count, int div, int h_w)
{
    int dim[1];
    dim[0] = total_count;
    CMat *result = CMat_create(1, dim);

    int i = 0;
    int offset = 0;
    int block = 0;
    int b_row = 0;
    int b_col = 0;
    int out_i = 0;
    int value = 0;
    for(i = 0; i < data_len; ++i) {
        offset = i % 0x10;
        block = i / (h_w * 16);
        b_row = offset * h_w;
        b_col = (i % (16 * h_w)) / 16;
        out_i = block * ( h_w * 16) + b_row + b_col;

        value = data_ptr[i];
        if ( value > 0x7f) {
            value = 0x80 - value;
        }
        if(out_i < total_count) {
            result->data_ptr[out_i] = value * 1.0 / div;
        }
    }
    return result;
}